package com.goldze.mvvmhabit.ui.feed;

import android.app.Application;
import android.databinding.ObservableField;
import android.databinding.ObservableInt;
import android.support.annotation.NonNull;
import android.text.TextUtils;

import com.goldze.mvvmhabit.data.DemoRepository;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.utils.ToastUtils;

public class FeedViewModel extends BaseViewModel<DemoRepository> {
    //反馈信息
    public ObservableField<String> feedInfo = new ObservableField<>("");
    //QQ
    public ObservableField<String> qq = new ObservableField<>("");
    //邮箱
    public ObservableField<String> email = new ObservableField<>("");

    //用户名清除按钮的显示隐藏绑定
    public ObservableInt clearBtnVisibility = new ObservableInt();

    public FeedViewModel(@NonNull Application application, DemoRepository repository) {
        super(application, repository);
    }

    //登录按钮的点击事件
    public BindingCommand feedOnClickCommand = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            login();
        }
    });

    /**
     * 网络模拟一个登陆操作
     **/
    private void login() {
        if (TextUtils.isEmpty(feedInfo.get())) {
            ToastUtils.showShort("请输入反馈信息！");
            return;
        }
        if (TextUtils.isEmpty(qq.get())) {
            ToastUtils.showShort("请输入QQ！");
            return;
        }
        if (TextUtils.isEmpty(email.get())) {
            ToastUtils.showShort("请输入email！");
            return;
        }

        ToastUtils.showShort("反馈成功");
        feedInfo.set("");
        qq.set("");
        email.set("");
        //        HTTPAPI.getInstance().login(userName.get(), password.get(), new StringCallback() {
        //            @Override
        //            public void onSuccess(String s, Call call, Response response) {
        //                LogUtil.e("注册-->" + s);
        //
        //                LoginBean loginBean = GsonUtil.INSTANCE.parse(s, LoginBean.class);
        //
        //
        //                SpUtils.put("module_token",loginBean.getResult().getToken());
        //                SpUtils.put("module_username", loginBean.getResult().getUser().getUsername());
        //                SpUtils.put("module_name", loginBean.getResult().getUser().getName());
        //                SpUtils.put("module_tel", loginBean.getResult().getUser().getMobile());
        //                SpUtils.put("module_schoolname", loginBean.getResult().getUser().getSchool());
        //                SpUtils.put("module_age", loginBean.getResult().getUser().getAge());
        //                SpUtils.put("module_student_number",loginBean.getResult().getUser().getNumber());
        //                startActivity(TabBarActivity.class);
        //                finish();
        //            }
        //        });

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}
